from langchain.embeddings import OpenAIEmbeddings

# 使用稳定API服务
embeddings = OpenAIEmbeddings(
    model="BAAI/bge-large-zh-v1.5",  # OpenAI推荐的经济高效模型
    openai_api_key="sk-pdfifkpjdlxvyvgkerbluaotktpznsmpbcvskjauotenxgvz",
    openai_api_base="https://api.siliconflow.cn/v1"  # 国内稳定的访问节点
)

# 输入文本
texts = ["This is a test.", "LangChain makes embeddings easy!"]

# 生成嵌入向量
vectors = embeddings.embed_documents(texts)

# 打印结果
for idx, vector in enumerate(vectors):
    print(f"Text {idx + 1}: {texts[idx]}")
    print(f"Embedding Vector: {vector[:5]}... (dim: {len(vector)})\n")
